package web.util;

import org.client.Client;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
	
	/**
	 * 校验邮箱是否合法
	 * 
	 * @param email
	 * @return
	 */
	public static boolean isEmail(String email) {
		String check = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
		Pattern regex = Pattern.compile(check);
		Matcher matcher = regex.matcher(email);
		return matcher.matches();
	}

    /**
     * 检验手机号是否合法
     * @param phone
     * @return
     */
	public static boolean isPhone(String phone) {
		String check = "^\\d{11}$";
		Pattern regex = Pattern.compile(check);
		Matcher matcher = regex.matcher(phone);
		return matcher.matches();
	}
	public static void main(String[] args) {
//		System.out.println(isPhone("1898621500"));
	}

	public static String[] getWords(String txt,String regex){
		String [] str = Client.fc(txt).split(" ");
		List<String> list = new ArrayList<String>();
		for (String s : str) {
			if(!s.endsWith(regex)){
				continue;
			}
			list.add(s.replace(regex,""));
		}
		return StringOperateUtil.toStringArray(list);
	}
}
